<!DOCTYPE html>
<html lang="en-US">

<script src="js/angular.min.js"></script>
<script src="js/ngStorage.min.js"></script>
<script src="js/plotly.min.js"></script>

<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet" href="css/bootstrap-theme.min.css">
<link rel="stylesheet" href="css/mb-frontend.css">

<head>
    <title>MacroBase Console</title>
</head>

<body>
<div>

    <div class="container-fluid">

        <div class="row">
            <div class="col-md-12" style="margin-top: 10px"><img src="macrobase.png" width=200/></div>

            <div class="col-md-12">
                <hr style="border-bottom: 10px solid black;"/>
            </div>
        </div>

        <div ng-app="consoleApp"
             data-ng-init="postgresstr='localhost'; pg_url='localhost';">

            <div ng-controller="errorController" class="row" ng-show="hasError()">
                <div class="col-md-12">
                    <div class="alert alert-danger" style="word-wrap: break-word;">
                        <h4><strong>An error occurred while processing your request:</strong></h4>
                        {{getError()}}
                        <br/>

                        <div style="margin-top: 1em">
                            <strong>Need help?</strong> Feel free to email <em>macrobase@cs.stanford.edu</em> (and
                            please include the above message)
                        </div>
                    </div>
                </div>
            </div>


            <div class="row">
                <div class="col-md-6">

                    <div ng-controller="connectController" ng-init="get_schema(true)">
                        <div class="panel panel-gray">
                            <div class="panel-heading">Database Configuration</div>
                            <div class="panel-body">
                                <table>
                                    <tr>
                                        <td nowrap style="width: 100px;">Database URL:</td>
                                        <td style="margin: 2px; width: 100%"><input ng-model="postgresstr"
                                                                                    style="width:100%">
                                        </td>
                                        <td>
                                            <button ng-click="updateDB()">submit</button>
                                        </td>
                                    </tr>
                                </table>
                                <table>
                                    <tr>
                                        <td nowrap style="width: 100px;">Base query:</td>
                                        <td style="margin: 2px; width:100%"><input ng-model="baseQuery"
                                                                                   style="width:100%">
                                        </td>
                                        <td>
                                            <button ng-click="updateDB()">submit</button>
                                        </td>
                                    </tr>
                                </table>

                            </div>
                        </div>
                        <br>

                        <div class="panel panel-gray">
                            <div class="panel-heading">Schema Information and Selection
                                <div style="float:right;">
                                    <button ng-click="clearSchema()">clear</button>
                                </div>
                                <div style="float:right;">
                                    <button ng-click="resetSchema()">reset</button>
                                </div>
                                <div style="float:right;">
                                    <button ng-click="sampleRows()">sample</button>
                                </div>
                            </div>
                            <div class="panel-body">

                                <div class="table-responsive">

                                    <table class="table" ng-controller="selectorController">
                                        <tr>
                                            <th>Explanatory<br>Attribute?</th>
                                            <th>Target Metric?<br>Lo/Hi</th>
                                            <th>Name</th>
                                            <th>Type</th>
                                        </tr>
                                        <tr ng-repeat="x in schemaCols.columns">
                                            <td>
                                                <button ng-click="selectedAttribute(x.name)" type="button"
                                                        ng-class="applyClassAttributeButton(x.name)"><span
                                                        id="{{x.name}}-attribute"
                                                        ng-class="applyClassAttributeGlyph(x.name)"
                                                        aria-hidden="true"></span>
                                                </button>
                                            </td>
                                            <td>
                                                <button ng-click="selectedMetric(x.name, false)" type="button"
                                                        ng-class="applyClassMetricButton(x.name, false)"><span
                                                        id="{{x.name}}-metric" class="glyphicon glyphicon-arrow-down"
                                                        aria-hidden="true"></span></button>
                                                <button ng-click="selectedMetric(x.name, true)" type="button"
                                                        ng-class="applyClassMetricButton(x.name, true)"><span
                                                        id="{{x.name}}-metric" class="glyphicon glyphicon-arrow-up"
                                                        aria-hidden="true"></span></button>
                                            </td>
                                            <td>{{x.name}}</td>
                                            <td>{{x.type}}</td>
                                        </tr>
                                    </table>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <div ng-controller="analyzeController" class="col-md-6"
                     data-ng-init="analyzeStr='Analyze'">
                    <button ng-click="triggerAnalyze()" type="button" class="btn btn-default btn-lg">
                        <span class="glyphicon glyphicon-flash" aria-hidden="true"></span> {{analyzeStr}}
                    </button>

                    <div class="panel panel-gray" ng-show="shouldShowAnalysis()" style="margin-top: 20px;">
                        <div class="panel-heading">
                            <h3 class="panel-title">Results</h3>
                        </div>

                        <div class="panel-body">
                            <div class="panel" style="margin-bottom: 0px">
                                <div class="panel-body" style="margin-bottom: 0px">
                                    <div class="table-responsive">
                                        <table class="table">
                                            <tr>
                                                <td># Outliers</td>
                                                <td>{{numOutliers}}</td>
                                            </tr>
                                            <tr>
                                                <td># Inliers</td>
                                                <td>{{numInliers}}</td>
                                            </tr>
                                            <tr>
                                                <td colspan="2"><b>Timing</b></td>
                                            </tr>
                                            <tr>
                                                <td>Load time</td>
                                                <td>{{loadTime}}ms</td>
                                            </tr>
                                            <tr>
                                                <td>Processing time</td>
                                                <td>{{executionTime}}ms</td>
                                            </tr>
                                            <tr>
                                                <td>Summarization time</td>
                                                <td>{{summarizationTime}}ms</td>
                                            </tr>
                                        </table>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <div id="overview_plot_panel" style="padding-left:15px; padding-top: 0px; padding-bottom: 10px;">
                                Overview Plot:<span ng-repeat="h in getPlotColumns()">
																<button ng-model="button" ng-click="preparePlotData(h)"
                                                                        ng-disabled="plotDataLoading">{{h}}
                                                                </button>
														</span>

                                <div id="plotArea" ng-hide="hidePlot"></div>
                            </div>
                        <div style="padding-left: 15px;">
                            Sort order:
                            <button ng-click="sortAnalysis('support')">support</button>
                            <button ng-click="sortAnalysis('ratioToInliers')">ratio</button>
                            <button ng-click="sortAnalysis('itemSize')">number of attributes</button>
                        </div>
                        <br>

                        <div class="panel panel-default" ng-repeat="i in itemsets">
                                <div ng-class="setSev(i.ratioToInliers)" id="explanation_{{$index}}">
                                    <div class="panel-body">
                                        <div class="col-sm-9">
                                        <table>
                                            <tr>
                                            <td>  <b>Attributes: </b> </td>
                                            <td>
                                                <span ng-repeat="item in i.items">
                                                {{item.column}}{{$last ? '' : ', '}}
                                                </span>
                                            </td>
                                            </tr>
                                            <tr style="width:100%">
                                                <td style="width:50%"><b>Ratio Out/In: </b></td>
                                                <td style="width:50%">{{i.ratioToInliers}}</td>
                                            </tr>
                                            <tr style="width:100%">
                                                <td style="width:50%"><b>Support: </b></td>
                                                <td style="width:50%"> {{i.support}}</td>
                                            </tr>
                                            <tr>
                                                <td style="width:50%"><b>Records: </b></td>
                                                <td style="width:50%"> {{i.numRecords}}</td>
                                            </tr>
                                        </table>
                                        </div>


                                        <div class="col-sm-2">
                                        <!--<button onclick="myFunction()">Click Me</button> -->
                                            <button ng-click="revealItemset($index)" type="button"><span
                                                    class="glyphicon glyphicon-chevron-down"></span></button>
                                        </div>

                                        <p></p>

                                        <div id="itemset_{{$index}}" class="itemsetHidden" style="padding-top:4px">
                                            <table class="table" style="margin-top: 100px">
                                                <tr>
                                                    <th style="width:50%">Column</th>
                                                    <th style="width:50%">Value</th>
                                                </tr>
                                                <tr ng-repeat="item in i.items">
                                                    <td>{{item.column}}</td>
                                                    <td>{{item.value}}</td>
                                                </tr>
                                            </table>
                                            <div>
                                                Plot: <div id="plotArea_{{$index}}" ng-hide="shouldHideItemsetPlot($index)"></div>
                                                <span ng-repeat="h in getPlotColumns()">
                                                        <button ng-model="button" ng-click="prepareItemsetPlotData(h, $parent.$index)" ng-disabled="plotDataLoading">{{h}}</button>
                                                </span>
                                            </div>
                                            <div style="padding: 15px; padding-top:30px;">
                                                <a ng-click="exploreItems(i.items)">Explore</a>
                                            </div>
                                        </div>

                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

</div>

<script src="consoleController.js"></script>

</body>
</html>
